package com.example.lab4.common;

import lombok.Data;


@Data
public class Result {
    private Boolean success;
    private Integer code;
    private String  message;
    private Object data;

    private Result(){}

    public static Result ok(){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS);
        result.setMessage("成功");
        return result;
    }

    public static Result error(){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(ResultCode.ERROR);
        result.setMessage("失败");
        return result;
    }
    public static Result ok(Object data){
        Result result = new Result();
        result.setSuccess(true);
        if(data!=null) result.setCode(ResultCode.SUCCESS);
        else result.setCode(ResultCode.ERROR);
        result.setMessage("成功");
        result.setData(data);
        return result;
    }
}
